package com.carb.controller.member;

import com.carb.dto.FeedbackUpdateDTO;
import com.carb.enums.FeedbackStatus;
import com.carb.result.Result;
import com.carb.service.IFeedbackService;
import com.carb.vo.FeedbackVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 评价管理 前端控制器
 * </p>
 *
 * @author XuChaoyang
 * @since 2025-02-22
 */
@RestController("memberFeedbackController")
@RequestMapping("/member/feedback")
@Tag(name = "评价管理相关接口")
@Slf4j
public class FeedbackController {

    @Resource
    private IFeedbackService feedbackService;

    /**
     * 会员自身待评价数量查询
     * @return 待评价数量
     */
    @GetMapping("/count")
    @Operation(summary = "会员自身待评价数量查询")
    public Result<Long> countFeedbackForMember() {
        log.info("会员自身待评价数量查询");
        Long count = feedbackService.countFeedbackForMember();
        log.info("会员自身待评价数量查询成功！");
        return Result.success(count);
    }

    /**
     * 会员自身评价查询
     * @param feedbackStatus 评价状态
     * @return 评价列表
     */
    @GetMapping("/list/{feedbackStatus}")
    @Operation(summary = "会员自身评价查询")
    public Result<List<FeedbackVO>> listFeedbackForMember(@PathVariable @Parameter(description = "评价状态") FeedbackStatus feedbackStatus) {
        log.info("会员自身评价查询：{}", feedbackStatus);
        List<FeedbackVO> feedbackList = feedbackService.listFeedbackForMember(feedbackStatus);
        log.info("会员自身评价查询成功！");
        return Result.success(feedbackList);
    }

    /**
     * 会员提交评价
     * @param feedbackUpdateDTO 会员提交的评价信息
     */
    @PutMapping
    @Operation(summary = "会员提交评价")
    public Result<String> updateFeedback(@RequestBody FeedbackUpdateDTO feedbackUpdateDTO) {
        log.info("会员提交评价信息：{}", feedbackUpdateDTO);
        feedbackService.updateFeedback(feedbackUpdateDTO);
        log.info("会员提交评价信息成功！");
        return Result.success();
    }

}
